#include <stdio.h>
#define MaxSize 100
typedef int DataType;
typedef struct {
    DataType  list[MaxSize];
    int size;
} SeqList;
void ListInitiate(SeqList *l){
    l->size=0;
}
int ListLength(SeqList L)
{
    return  L.size;

}
int ListInsert(SeqList *L, int i, DataType x){
    int j;
    static int flag = 0;
    if(L->size >= MaxSize){
        printf("顺序表已满无法插入！\n");
        return 0;
    } else if(i < 0 || i > L->size){
        if(flag == 0){
            printf("参数i不合法\n");
            flag = 1;
        }
        return 0;
    } else {
        for (j = L->size; j > i; j--) {
            L->list[j] = L->list[j - 1];
        }
        L->list[i] = x;
        L->size++;
        return 1;
    }
}

int ListDelete(SeqList *L, int i, DataType *x){
    int j;
    if(L->size <= 0){
        printf("顺序表已空无数据元素可删！\n");
        return 0;
    } else if(i < 0 || i >= L->size){
        printf("参数i不合法");
        return 0;
    } else {
        *x = L->list[i];
        for (j = i; j < L->size - 1; j++) {
            L->list[j] = L->list[j + 1];
        }
        L->size--;
        return 1;
    }
}

int ListGet(SeqList L, int i, DataType *x){
    if(i < 0 || i >= L.size){
        printf("参数i不合法！\n");
        return 0;
    } else {
        *x = L.list[i];
        return 1;
    }
}
int ListSearch(SeqList L,DataType x){
    int i;
    for ( i = 0; i <L.size ; ++i) {
        if(L.list[i]==x){
            return i;
        }
    }
    return -1;

}
int  main(int argc,char*argv[]){
    SeqList  myList;
    int i,x;
    ListInitiate(&myList);
    for (int i = 0; i < 10; ++i)
        ListInsert( &myList,i,i+1);
        ListDelete(&myList,4,&x);
    int index = ListSearch(myList, x);

    for (int i = 0; i < ListLength(myList) ; ++i) {
            ListGet(myList,i,&x);
            printf("%d  ",x);
    } printf("\n");
    printf("the index value of the number 9: %d\n", ListSearch(myList, 9));
    printf("the index value of the number 11 :%d\n", ListSearch(myList, 11));

    return  0;
}